﻿using System;
using System.Drawing;
using System.ComponentModel;

using SharpGL.Media3D;
using SharpGL.SceneGraph.Primitives.Text;

namespace SharpGL.SceneGraph.Primitives.SmartAxies
{
    [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class AxisCaption2D : INotifyPropertyChanged
    {
        #region Private Fields

        private static Font defaultFont = new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Bold);

        private bool visible = true;
        private GLColor color = new GLColor(1.0f, 1.0f, 1.0f, 1.0f);

        private Text2DObject textObject = new Text2DObject()
            {
                Font = defaultFont,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

        #endregion Private Fields

        #region Protected Methods

        /// <summary>
        /// Call this function to do the PropertyChanged event.
        /// </summary>
        protected virtual void NotifyPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion Protected Methods

        #region Public Constructors

        public AxisCaption2D()
        {
        }

        #endregion Public Constructors

        #region Public Events

        [Description("Called when properties has been changed."), Category("SharpGL")]
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion Public Events

        #region Protected Properties

        protected Text2DObject TextObject
        {
            get { return textObject; }
        }

        #endregion Protected Properties

        #region Public Properties

        [Description("Visible"), Category("Axis caption")]
        public bool Visible
        {
            get { return visible; }
            set
            {
                if (visible != value)
                {
                    visible = value;

                    NotifyPropertyChanged("Visible");
                }
            }
        }

        [Description("Color"), Category("Axis caption")]
        public GLColor Color
        {
            get { return color; }
            set
            {
                if (color != value)
                {
                    color = value;

                    NotifyPropertyChanged("Color");
                }
            }
        }

        [Description("Font"), Category("Axis caption")]
        public Font Font
        {
            get { return textObject.Font; }
            set
            {
                if (!textObject.Font.Equals(value))
                {
                    if (value == null)
                        textObject.Font = defaultFont;
                    else
                        textObject.Font = value;

                    NotifyPropertyChanged("Font");
                }
            }
        }

        [Description("HorizontalAlignment"), Category("Axis caption")]
        public HorizontalAlignment HorizontalAlignment
        {
            get { return textObject.HorizontalAlignment; }
            set
            {
                if (textObject.HorizontalAlignment != value)
                {
                    textObject.HorizontalAlignment = value;

                    NotifyPropertyChanged("HorizontalAlignment");
                }
            }
        }

        [Description("VerticalAlignment"), Category("Axis caption")]
        public VerticalAlignment VerticalAlignment
        {
            get { return textObject.VerticalAlignment; }
            set
            {
                if (textObject.VerticalAlignment != value)
                {
                    textObject.VerticalAlignment = value;

                    NotifyPropertyChanged("VerticalAlignment");
                }
            }
        }

        #endregion Public Properties
    }
}
